import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

var router=new VueRouter({
        routes:[
                {path:"/",redirect:"/login"},
                {path:"/home",component:()=>import('../views/Home/Home.vue')},
                {path:"/category",component:()=>import('../views/Category/Category.vue'),meta:{needLogin:true}},
                {path:"/cart/",component:()=>import('../views/Cart/Cart.vue'),meta:{needLogin:true}},
                {path:"/login",component:()=>import('../views/Login/Login.vue')},
                {path:"/list/:cid",component:()=>import('../views/List/List.vue')},
                {path:"/detail/:cid",component:()=>import('../views/Detail/Detail.vue')},
                {path:"/address",component:()=>import('../views/Address/Address.vue')},
                {path:"/profile",component:()=>import('../views/Profile/Profile.vue')},
                {path:"/order",component:()=>import('../views/Order/Order.vue')},
                {path:"/myorder",component:()=>import('../views/myoder/myorder.vue')},
                {path:"/pay/:cid",component:()=>import('../views/Pay/Pay.vue')}
        ]
});
router.beforeEach((to,from,next) => {
        if(to.meta.needLogin && !sessionStorage.getItem('token')){
                next(`/login?target=${to.fullPath}`);
        }
        else
                next()
});
export  default router;